//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.recruit.g1.common.model;

import com.recruit.g1.common.enums.ErrorCodeSupport;
import com.recruit.g1.common.exception.BusinessException;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;

/***
 * 此类用于Controller封装返回给vue前端页面数据的类
 * @param <T>
 */
@ApiModel("全局http接口返回实体")
public class Result<T> implements Serializable {
    private static final long serialVersionUID = 2463268310118367610L;
    @ApiModelProperty("0 代表成功, 其他均为失败")
    private String code;
    @ApiModelProperty("描述")
    private String message;
    @ApiModelProperty("真正实体")
    private T data;
    private static Result<Void> ok = new Result<Void>();

    private Result() {
        this.code = "0";
        this.message = "success";
    }

    public static Result<Void> success() {
        return new Result<Void>();
    }

    public Result(T data) {
        if (data instanceof ErrorCodeSupport) {
            ErrorCodeSupport error = (ErrorCodeSupport)data;
            this.code = error.getCode();
            this.message = error.getMessage();
        } else {
            this.code = "0";
            this.data = data;
        }

    }

    private Result(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public static Result fail() {
        String code = "-1";
        String msg = "system error";
        return new Result(code, msg);
    }

    public static Result fail(BusinessException businessException) {
        return new Result(businessException.getCode(), businessException.getMessage());
    }

    public static Result fail(ErrorCodeSupport errorSupport) {
        return new Result(errorSupport.getCode(), errorSupport.getMessage());
    }

    public static Result fail(String code, String message) {
        return new Result(code, message);
    }

    public boolean isSuccess() {
        return this.code.equals("0");
    }

    public String getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

    public T getData() {
        return this.data;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean equals(Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof Result)) {
            return false;
        } else {
            Result<?> other = (Result)o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                Object this$code = this.getCode();
                Object other$code = other.getCode();
                if (this$code == null) {
                    if (other$code != null) {
                        return false;
                    }
                } else if (!this$code.equals(other$code)) {
                    return false;
                }

                Object this$message = this.getMessage();
                Object other$message = other.getMessage();
                if (this$message == null) {
                    if (other$message != null) {
                        return false;
                    }
                } else if (!this$message.equals(other$message)) {
                    return false;
                }

                Object this$data = this.getData();
                Object other$data = other.getData();
                if (this$data == null) {
                    if (other$data != null) {
                        return false;
                    }
                } else if (!this$data.equals(other$data)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof Result;
    }

    public int hashCode() {
        int PRIME = 59;
        int result = 1;
        Object $code = this.getCode();
        result = result * 59 + ($code == null ? 43 : $code.hashCode());
        Object $message = this.getMessage();
        result = result * 59 + ($message == null ? 43 : $message.hashCode());
        Object $data = this.getData();
        result = result * 59 + ($data == null ? 43 : $data.hashCode());
        return result;
    }

    public String toString() {
        return "Result(code=" + this.getCode() + ", message=" + this.getMessage() + ", data=" + this.getData() + ")";
    }

    public Result(String code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
}
